<script setup lang="ts">
import { ref, onMounted } from 'vue'
import HomePanel from './HomePanel.vue'
import GoodsItem from './GoodsItem.vue'
import { getGoodsListApi } from '@/apis/home'
import type { HomeGoodsType } from '@/apis/components/homeType'

// 获取商品数据列表
const goodsList = ref<[HomeGoodsType]>()
const getGoods = async () => {
  const res = await getGoodsListApi()
  goodsList.value = res.data.result
}
onMounted(() => getGoods())
</script>

<template>
  <div class="home-product">
    <HomePanel :title="item.name" v-for="item in goodsList" :key="item.id">
      <div class="boxx">
        <RouterLink to="/" class="one">
          <img :src="item.picture" alt="" />
          <div class="pname">
            <p>{{ item.name }}馆</p>
            <p>{{ item.saleInfo }}</p>
          </div>
        </RouterLink>
        <ul>
          <li v-for="goods in item.goods" :key="goods.id">
            <GoodsItem :goods="goods" />
          </li>
        </ul>
      </div>
    </HomePanel>
  </div>
</template>

<style lang="scss" scoped>
.home-product {
  margin-top: 20px;
  .boxx {
    display: flex;
    .one {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;
      img {
        width: 240px;
        height: 610px;
      }
      .pname {
        position: absolute;
        top: 305px;
        left: 0;
        display: flex;
        font-size: 19px;
        color: white;
        background-color: rgba(0, 0, 0, 0.379);
        p {
          padding-right: 10px;
        }
      }
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      li {
        list-style: none;
      }
    }
  }
}
</style>
